package com.taxi.driver.module.main.mine.setting.volume;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.taxi.driver.R;
import com.taxi.driver.common.Application;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.module.main.mine.setting.volume.dagger.DaggerVolumeComponent;
import com.taxi.driver.module.main.mine.setting.volume.dagger.VolumeModule;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class VolumeActivity extends BaseActivity implements VolumeContract.View, SeekBar.OnSeekBarChangeListener {

    @BindView(R.id.rl_system_volume)
    RelativeLayout rl_system_volume;
    @BindView(R.id.tv_system_volume)
    TextView tv_system_volume;
    @BindView(R.id.iv_hook1)
    ImageView iv_hook1;
    @BindView(R.id.rl_immobilization_volume)
    RelativeLayout rl_immobilization_volume;
    @BindView(R.id.tv_immobilization_volume)
    TextView tv_immobilization_volume;
    @BindView(R.id.iv_hook2)
    ImageView iv_hook2;
    @BindView(R.id.seek_bar)
    SeekBar seek_bar;

    @Inject
    VolumePresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volume);
        ButterKnife.bind(this);
        seek_bar.setOnSeekBarChangeListener(this);

        DaggerVolumeComponent.builder()
                .appComponent(Application.getAppComponent())
                .volumeModule(new VolumeModule(this))
                .build().inject(this);

        if (!mPresenter.isImmobilizationVolum()) {
            selectSystemVolume();
        } else {
            selectImmobilizationVolume();
            seek_bar.setProgress(mPresenter.getImmobilizationVolumeSize());
        }

    }

    @OnClick({R.id.rl_system_volume, R.id.rl_immobilization_volume})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_system_volume:
                selectSystemVolume();
                mPresenter.setVolumeType(false);
                mPresenter.setSystemVolumeSize(100 * getSystemVolume() / getMaxSystemVolume());
                break;
            case R.id.rl_immobilization_volume:
                selectImmobilizationVolume();
                mPresenter.setVolumeType(true);
                seek_bar.setProgress(mPresenter.getImmobilizationVolumeSize());
                break;
            case R.id.btn_withdrawal:

                break;
        }
    }

    private void selectSystemVolume() {
        tv_system_volume.setTextColor(getResources().getColor(R.color.text_4f5a67));
        tv_immobilization_volume.setTextColor(getResources().getColor(R.color.text_9ea7b1));
        iv_hook1.setVisibility(View.VISIBLE);
        iv_hook2.setVisibility(View.GONE);
        seek_bar.setVisibility(View.GONE);
    }

    private void selectImmobilizationVolume() {
        tv_system_volume.setTextColor(getResources().getColor(R.color.text_9ea7b1));
        tv_immobilization_volume.setTextColor(getResources().getColor(R.color.text_4f5a67));
        iv_hook1.setVisibility(View.GONE);
        iv_hook2.setVisibility(View.VISIBLE);
        seek_bar.setVisibility(View.VISIBLE);
    }

    @Override
    public boolean isActive() {
        return false;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (mPresenter.isImmobilizationVolum())
            mPresenter.setImmobilizationVolumeSize(progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}
